<template>
  <div class="header">
    <el-card class="card">
      <div class="card-header">
        <span>工单总数</span>
        <span>
          <i class="el-icon-warning-outline"></i>
        </span>
      </div>
      <div class="card-footer">
        <i v-if="isShow" class="el-icon-loading"></i>
        <span v-else>{{list.OLderSum}}</span>
      </div>
    </el-card>
    <el-card class="card">
      <div class="card-header">
        <span>我创建的</span>
        <span>
          <i class="el-icon-warning-outline"></i>
        </span>
      </div>
      <div class="card-footer">
        <i v-if="isShow" class="el-icon-loading"></i>
        <span v-else>{{list.adminOlders}}</span>
      </div>
    </el-card>
    <el-card class="card">
      <div class="card-header">
        <span>处理中</span>
        <span>
          <i class="el-icon-warning-outline"></i>
        </span>
      </div>
      <div class="card-footer">
        <i v-if="isShow" class="el-icon-loading"></i>
        <span v-else>{{ worker}}</span>
      </div>
    </el-card>
    <el-card class="card">
      <div class="card-header">
        <span>已完成</span>
        <span>
          <i class="el-icon-warning-outline"></i>
        </span>
      </div>
      <div class="card-footer">
        <i v-if="isShow" class="el-icon-loading"></i>
        <span v-else>{{finish}}</span>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: [
        // { isPayment: 0, amount: 3 },
        // { isPayment: 2, amount: 1 },
      ],
      finish: 0,
      worker: 0,
      isShow: false,
    };
  },
  computed: {
    totalAmount() {
      return this.list.length == 0
        ? 0
        : this.list
            .map((item) => item.amount)
            .reduce((prev, curr) => prev + curr, 0);
    },
    currentAmount() {
      return function (type) {
        let amount = 0;
        this.list.forEach((item) => {
          if (item.isPayment === type) {
            amount = item.amount;
            return;
          }
        });
        return amount;
      };
    },
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      this.isShow = true;
      setTimeout(() => {
        this.isShow = false;
      }, 2000);

      this.$axios
        .get("/nces/ncesOlders", {
          params: {
            adminName: this.$store.state.user.username,
          },
        })
        .then((res) => {
            console.log(res);
          this.list = res.data.result;
          this.finish = this.list.olderCount[2];
          this.worker = this.list.olderCount[1];
          if(this.finish==undefined){
            this.finish=0
          }
          if (this.worker==undefined) {
            this.worker=0
          }
        })
        .catch((e) => console.log(e));
    },
  },
};
</script>

<style scoped>
.header {
  width: 100%;
  height: 90px;
  margin: 0 auto 10px;
  display: flex;
  justify-content: space-evenly;
}
.card {
  width: 24%;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: 5px;
  line-height: 1.2;
}
.card-footer {
  width: 100%;
  text-align: center;
  font-size: 1.2rem;
  font-family: "Times New Roman", Times, serif;
  border-bottom: 1px solid rgb(192, 190, 190);
}
</style>
